←Select platform

Run(List<IFeature>,LEADDocument,CancellationToken) Method

Summary

Asynchronous method to run the list of features on a LEADDocument, returning results of processing.

Syntax
C#
C++/CLI
Python
public Task<List<ElementSetResult>> Run( 
   List<IFeature> features, 
   LEADDocument document, 
   CancellationToken token 
) 
public:  
   Task<List<ElementSetResult^>^>^ Run( 
       List<IFeature^>^ features, 
      LEADDocument^ document, 
      CancellationToken^ token 
   ) 
def Run(self,features,document,token): 

Parameters

features

List of features to run on the document.

document

Document on which the features are run.

token

A CancellationToken enables cooperative cancellation between threads or Task objects. Create a cancellation token by instantiating a CancellationTokenSource object, which manages cancellation tokens retrieved from its CancellationTokenSource.

Return Value

The results of processing the document.

Example

This example runs a ruleset on a document and reads the results.

C#
Java
using Leadtools; 
using Leadtools.Document.Unstructured; 
using Leadtools.Document.Analytics; 
 
using Leadtools.Document.Unstructured.Highlevel; 
using Leadtools.Ocr; 
using Leadtools.Document; 
 
       
async Task RunRuleSet(string ruleSetFileName, string documentFileName, IOcrEngine ocrEngine) 
{ 
   var json = LoadJson(ruleSetFileName); 
   var features = FeatureResourceBuilder.BuildFromArray(json); 
 
   var doc = LoadDocument(documentFileName); 
   doc.Text.OcrEngine = ocrEngine; 
   doc.Text.ImagesRecognitionMode = DocumentTextImagesRecognitionMode.Auto; 
   doc.Text.TextExtractionMode = DocumentTextExtractionMode.Auto; 
 
   var results = await new FeaturesProcessingEngine().Run(features.ToList(), doc, 1, 1, CancellationToken.None); 
 
   foreach (var result in results) 
   { 
      var items = result?.Items; 
      foreach (var item in items) 
      { 
         var name = item?.ElementName; 
         var val = item?.Value; 
      } 
   } 
 
   string LoadJson(string pathName) 
   { 
      var txt = File.ReadAllText(pathName); 
      var obj = JObject.Parse(txt); 
      var meta = obj["meta"]; 
      if (null == meta) 
      { 
         throw new Exception("Couldn't find the meta info in the ruleset file, make sure this file was saved using this demo."); 
      } 
      return meta.ToString(); 
   } 
 
   LEADDocument LoadDocument(string pathName) 
   { 
      var options = new LoadDocumentOptions() 
      { 
         FirstPageNumber = 1, 
         LastPageNumber = -1, 
         TimeoutMilliseconds = 0, 
         MaximumImagePixelSize = 12288 
      }; 
 
      return DocumentFactory.LoadFromFile(pathName, options); 
   } 
} 
 
import java.io.File; 
import java.io.FileReader; 
import java.io.IOException; 
 
import java.util.List; 
import java.util.Scanner; 
 
import org.junit.*; 
import org.junit.runner.JUnitCore; 
import org.junit.runner.Result; 
import org.junit.runner.notification.Failure; 
 
import com.google.gson.JsonObject; 
import com.google.gson.JsonElement; 
import com.google.gson.JsonParser; 
 
import leadtools.*; 
import leadtools.document.DocumentFactory; 
import leadtools.document.DocumentTextExtractionMode; 
import leadtools.document.DocumentTextImagesRecognitionMode; 
import leadtools.document.LEADDocument; 
import leadtools.document.LoadDocumentOptions; 
import leadtools.document.analytics.ElementResult; 
import leadtools.document.analytics.ElementSetResult; 
import leadtools.document.analytics.internal.ApproximateRegexMode; 
import leadtools.document.unstructured.RegexInspectorElement; 
import leadtools.document.unstructured.RegexParameters; 
import leadtools.document.unstructured.highlevel.FeatureResourceBuilder; 
import leadtools.document.unstructured.highlevel.FeaturesProcessingEngine; 
import leadtools.document.unstructured.highlevel.IFeature; 
import leadtools.ocr.OcrEngine; 
 
 
// SKIPPING DUE TO ASYNC 
Requirements

Target Platforms

Help Version 23.0.2024.2.29
Products | Support | Contact Us | Intellectual Property Notices
© 1991-2024 LEAD Technologies, Inc. All Rights Reserved.

Leadtools.Document.Unstructured Assembly
Products | Support | Contact Us | Intellectual Property Notices
© 1991-2023 LEAD Technologies, Inc. All Rights Reserved.